package com.atguigu.tingshu.payment.api;

import com.atguigu.tingshu.common.login.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.payment.service.WxPayService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "微信支付接口")
@RestController
@RequestMapping("api/payment")
@Slf4j
public class WxPayApiController {

    @Autowired
    private WxPayService wxPayService;




    @PostMapping("/wxPay/notify")
    public Map<String,String> paySuccessNotify(HttpServletRequest request){


        return wxPayService.paySuccessNotify(request);
    }

    //api/payment/wxPay/createJsapi/1301/23feda547c7145f894f3f5dd51216475 post
    @PostMapping("/wxPay/createJsapi/{paymentType}/{orderNo}")
    @GuiGuLogin
    public Result<Map<String,String>> createJsapi(@PathVariable("orderNo")String paymentType, @PathVariable("orderNo") String orderNo){
        Map<String,String> map = wxPayService.createJsapi(paymentType,orderNo);
        return Result.ok(map);
    }
    //api/payment/wxPay/queryPayStatus/5ad9279a2e2f4eeb99d7e3dcb30e938e get
    @GetMapping("/wxPay/queryPayStatus/{orderNo}")
    public Result<Boolean> queryPayStatus(@PathVariable String orderNo){
        Boolean status = wxPayService.queryPayStatus(orderNo);
        return Result.ok(status);
    }
}
